const Router = require("koa-router");
/* 模块自动导入 */
const AutoDir = require("require-directory");
const cors = require("koa2-cors");
const { koaBody } = require("koa-body");
const onerror = require('koa-onerror');
const logger = require("koa-logger");
function initManage(app) {
      onerror(app);
      app.use(logger());
      /* 跨域中间件配置 */
      app.use(cors());
      /* koaBody模块配置 可以实现跨域和图片上传 */
      app.use(koaBody());
      const useRoutes = (obj) => {
            if (obj instanceof Router) {
                  app.use(obj.routes())
            }
      }
      AutoDir(module, process.cwd() + "/router", { visit: useRoutes })
}
module.exports = initManage;